home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Misc / IconBounce / Source / IconApp.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  2.2 KB  |  79 lines

  1. #import "IconApp.h"
  2. #import <appkit/Window.h>
  3. #import "Animator.h"
  4. #import "BounceView.h"
  5. #import <defaults/defaults.h>
  6. #import <stdlib.h>
  7. #import <appkit/Bitmap.h>
  8. #import <appkit/Control.h>
  9.  
  10. @implementation IconApp
  11.  
  12. + new            // create the new application, and make us its delegate.
  13. {
  14.   self = [super new];
  15.   [self setDelegate:self];
  16.   return self;
  17. }
  18. - setIconView:anObject        // let me know where the view is.
  19.                 // Note that the View is in the Speed window,
  20.                 // but "hidden" below the bottom.  Resize from
  21.                 // IB to "find" it.  Size makes no difference here.
  22.                 // It may not need to be hidden, either, as it
  23.                 // is moved right away anyway.
  24. {
  25.   iconView=anObject;
  26.   return self;
  27. }
  28. - setSpeedSlider:anObject    // let me know where the slider is.
  29. {
  30.   speedSlider=anObject;
  31.   return self;
  32. }
  33. - appDidInit:sender            // set up in the icon, and set the timing.
  34. {
  35.   NXRect r;
  36.   const char *t;
  37.   
  38.   id win=[self appIcon];            // get the appIcon.
  39.   [[win contentView] getBounds:&r];    // find region for BounceView.
  40.   NXInsetRect( &r, 8, 8);
  41.   [[win contentView] addSubview:iconView];    // move it to icon.
  42.   [iconView moveTo:r.origin.x :r.origin.y];    // position and size the view.
  43.   [iconView sizeTo:r.size.width :r.size.height];
  44.   
  45.   NXInsetRect( &r, -4, -4);            // place the inactive bitmap.
  46.   [[win contentView] lockFocus];
  47.   [[[Bitmap findBitmapFor:"inactive"] composite:NX_SOVER toPoint:&r.origin] free];
  48.   [[win contentView] unlockFocus];
  49.   
  50.   if( t=NXGetDefaultValue( [NXApp appName], "Speed"))    // set the speed.
  51.     [[iconView animator] setTiming:atof( t)];
  52.   [[iconView animator] start:iconView];        // and start the animator.
  53.   
  54.   [speedSlider setDoubleValue:[[iconView animator] timing]];    // fix the slider.
  55.   
  56.   return self;
  57. }
  58. - terminate:sender            // store the defaults, and go away.
  59. {
  60.   char s[ 20];
  61.   sprintf( s, "%f", [[iconView animator] timing]);    // write to string,
  62.   NXWriteDefault( [self appName], "Speed", s);        // and store it.
  63.   return [super terminate:sender];
  64. }
  65. - appPowerOffIn:(int)ms andSave:(int)aFlag    // catch Workspace logout.
  66. {
  67.   return [self terminate:self];
  68. }
  69.  
  70. - windowWillResize:sender toSize:(NXSize *)s    // Just limits a window's size.
  71. {
  72.   NXRect r;
  73.   [sender getFrame:&r];
  74.   s->height=r.size.height;            // kindly change it back.
  75.   return self;
  76. }
  77.  
  78. @end
  79.